/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:17
*/
KISSY.add("date/gregorian/const",[],function(){return{SUNDAY:0,MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6,JANUARY:0,FEBRUARY:1,MARCH:2,APRIL:3,MAY:4,JUNE:5,JULY:6,AUGUST:7,SEPTEMBER:8,OCTOBER:9,NOVEMBER:10,DECEMBER:11}});
KISSY.add("date/gregorian/utils",["./const"],function(p,A){var e=A("./const"),y=[0,31,59,90,120,151,181,212,243,273,304,334],t=[0,31,60,91,121,152,182,213,244,274,305,335],q={};p.mix(q,{isLeapYear:function(e){return 0!==(e&3)?!1:0!==e%100||0===e%400},mod:function(e,g){return e-g*k(e/g)},getFixedDate:function(e,g,h){var i=e-1;return 365*i+k(i/4)-k(i/100)+k(i/400)+(h+(n(e)?t[g]:y[g]))},getGregorianDateFromFixedDate:function(m){var g,h,i,j;h=m-1;g=k(h/146097);i=z(h,146097);h=k(i/36524);j=z(i,36524);
i=k(j/1461);j=z(j,1461);j=k(j/365);g=400*g+100*h+4*i+j;4===h||4===j||++g;i=q.getFixedDate(g,e.JANUARY,1);j=(h=n(g))?t:y;var p=m-i,u,l;for(l=0;l<j.length;l++)if(j[l]<=p)u=l;else break;i=m-i-j[u]+1;m=0<=m?m%7:z(m,7);return{year:g,month:u,dayOfMonth:i,dayOfWeek:m,isLeap:h}}});var k=Math.floor,n=q.isLeapYear,z=q.mod;return q});
KISSY.add("date/gregorian",["./gregorian/utils","i18n!date","./gregorian/const"],function(p,A){function e(a,b){var c=p.makeArray(arguments);p.isObject(a)?(b=a,a=b.timezoneOffset):3<=c.length&&(a=b=null);this.locale=b=b||z;this.fields=[];this.time=void 0;this.timezoneOffset=a||b.timezoneOffset;this.firstDayOfWeek=b.firstDayOfWeek;this.minimalDaysInFirstWeek=b.minimalDaysInFirstWeek;this.fieldsComputed=!1;3<=arguments.length&&this.set.apply(this,c)}function y(a){var b=a.fields,c=t(b[g],b[h]);b[i]>c&&
a.set(i,c)}function t(a,b){return B(a)?I[b]:J[b]}function q(a,b,c){var d=b+6-r(b+6-a.firstDayOfWeek,7);d-b>=a.minimalDaysInFirstWeek&&(d-=7);return F((c-d)/7)+1}var k=parseInt,n=A("./gregorian/utils"),z=A("i18n!date"),m=A("./gregorian/const");p.mix(e,m);p.mix(e,{Utils:n,isLeapYear:n.isLeapYear,YEAR:1,MONTH:2,DAY_OF_MONTH:3,HOUR_OF_DAY:4,MINUTES:5,SECONDS:6,MILLISECONDS:7,WEEK_OF_YEAR:8,WEEK_OF_MONTH:9,DAY_OF_YEAR:10,DAY_OF_WEEK:11,DAY_OF_WEEK_IN_MONTH:12,AM:0,PM:1});var g=e.YEAR,h=e.MONTH,i=e.DAY_OF_MONTH,
j=e.HOUR_OF_DAY,E=e.MINUTES,u=e.SECONDS,l=e.MILLISECONDS,C=e.DAY_OF_WEEK_IN_MONTH,v=e.DAY_OF_YEAR,x=e.DAY_OF_WEEK,s=e.WEEK_OF_MONTH,o=e.WEEK_OF_YEAR,J=[31,28,31,30,31,30,31,31,30,31,30,31],I=[31,29,31,30,31,30,31,31,30,31,30,31],r=n.mod,B=n.isLeapYear,F=Math.floor,G=[void 0,1,e.JANUARY,1,0,0,0,0,1,void 0,1,e.SUNDAY,1],H=[void 0,292278994,e.DECEMBER,void 0,23,59,59,999,void 0,void 0,void 0,e.SATURDAY,void 0];e.prototype={constructor:e,isLeapYear:function(){return B(this.getYear())},getLocale:function(){return this.locale},
getActualMinimum:function(a){if(void 0!==G[a])return G[a];var b=this.fields;if(a===s)return(new e(b[g],b[h],1)).get(s);throw Error("minimum value not defined!");},getActualMaximum:function(a){if(void 0!==H[a])return H[a];var b,c=this.fields;switch(a){case i:b=t(c[g],c[h]);break;case o:b=(new e(c[g],e.DECEMBER,31)).get(o);1===b&&(b=52);break;case s:b=(new e(c[g],c[h],t(c[g],c[h]))).get(s);break;case v:b=B(c[g])?366:365;break;case C:b=k((t(c[g],c[h])-1)/7)+1}if(void 0===b)throw Error("maximum value not defined!");
return b},isSet:function(a){return void 0!==this.fields[a]},computeFields:function(){var a=this.time,b=6E4*this.timezoneOffset,c=k(b/864E5),b=b%864E5,c=c+k(a/864E5),b=b+a%864E5;if(864E5<=b)b-=864E5,c++;else for(;0>b;)b+=864E5,c--;var c=c+719163,d=n.getGregorianDateFromFixedDate(c),f=d.year,a=this.fields;a[g]=f;a[h]=d.month;a[i]=d.dayOfMonth;a[x]=d.dayOfWeek;0!==b?(a[j]=k(b/36E5),b%=36E5,a[E]=k(b/6E4),b%=6E4,a[u]=k(b/1E3),a[l]=b%1E3):a[j]=a[E]=a[u]=a[l]=0;var w=n.getFixedDate(f,e.JANUARY,1),b=c-d.dayOfMonth+
1;a[v]=c-w+1;a[C]=k((d.dayOfMonth-1)/7)+1;d=q(this,w,c);0===d?(d=w-1,f=w-(B(f-1)?366:365),d=q(this,f,d)):52<=d&&(f=w+(B(f)?366:365),w=f+6-r(f+6-this.firstDayOfWeek,7),w-f>=this.minimalDaysInFirstWeek&&c>=w-7&&(d=1));a[o]=d;a[s]=q(this,b,c);this.fieldsComputed=!0},computeTime:function(){if(!this.isSet(g))throw Error("year must be set for KISSY GregorianCalendar");var a=this.fields,b=a[g],c=0;this.isSet(j)&&(c+=a[j]);c=60*c+(a[E]||0);c=60*c+(a[u]||0);c=1E3*c+(a[l]||0);a[g]=b;a=0+this.getFixedDate();
this.time=c=864E5*(a-719163)+c-6E4*this.timezoneOffset;this.computeFields()},complete:function(){void 0===this.time&&this.computeTime();this.fieldsComputed||this.computeFields()},getFixedDate:function(){var a=this.fields,b=this.firstDayOfWeek,c=a[g],d=e.JANUARY;this.isSet(h)&&(d=a[h],d>e.DECEMBER?(c+=k(d/12),d%=12):d<e.JANUARY&&(c+=F(d/12),d=r(d,12)));var f=n.getFixedDate(c,d,1),j=this.firstDayOfWeek;this.isSet(x)&&(j=a[x]);this.isSet(h)?this.isSet(i)?f+=a[i]-1:this.isSet(s)?(c=f+6-r(f+6-b,7),c-f>=
this.minimalDaysInFirstWeek&&(c-=7),j!==b&&(c=c+6-r(c+6-j,7)),f=c+7*(a[s]-1)):(a=this.isSet(C)?a[C]:1,b=7*a,0>a&&(b=t(c,d)+7*(a+1)),f=f+b-1-r(f+b-1-j,7)):this.isSet(v)?f+=a[v]-1:(c=f+6-r(f+6-b,7),c-f>=this.minimalDaysInFirstWeek&&(c-=7),j!==b&&(c=c+6-r(c+6-j,7)),f=c+7*(a[o]-1));return f},getTime:function(){void 0===this.time&&this.computeTime();return this.time},setTime:function(a){this.time=a;this.fieldsComputed=!1;this.complete()},get:function(a){this.complete();return this.fields[a]},set:function(a,
b){var c=arguments.length;if(2===c)this.fields[a]=b;else if(c<l+1)for(var d=0;d<c;d++)this.fields[g+d]=arguments[d];else throw Error("illegal arguments for KISSY GregorianCalendar set");this.time=void 0},add:function(a,b){if(b){var c=this.fields,d=this.get(a);if(a===g)this.set(g,d+b),y(this);else if(a===h){var d=d+b,e=F(d/12),d=r(d,12);e&&this.set(g,c[g]+e);this.set(h,d);y(this)}else{switch(a){case j:b*=36E5;break;case E:b*=6E4;break;case u:b*=1E3;break;case l:break;case s:case o:case C:b*=6048E5;
break;case x:case v:case i:b*=864E5;break;default:throw Error("illegal field for add");}this.setTime(this.time+b)}}},getRolledValue:function(a,b,c,d){d=d-c+1;return c+(a-c+b%d+d)%d},roll:function(a,b){if(b){var c=this.get(a),d=this.getActualMinimum(a),e=this.getActualMaximum(a),c=this.getRolledValue(c,b,d,e);this.set(a,c);switch(a){case h:y(this);break;default:this.updateFieldsBySet(a)}}},updateFieldsBySet:function(a){var b=this.fields;switch(a){case s:b[i]=void 0;break;case v:b[h]=void 0;break;case x:b[i]=
void 0;break;case o:b[v]=void 0,b[h]=void 0}},getTimezoneOffset:function(){return this.timezoneOffset},setTimezoneOffset:function(a){this.timezoneOffset!==a&&(this.fieldsComputed=void 0,this.timezoneOffset=a)},setFirstDayOfWeek:function(a){this.firstDayOfWeek!==a&&(this.firstDayOfWeek=a,this.fieldsComputed=!1)},getFirstDayOfWeek:function(){return this.firstDayOfWeek},setMinimalDaysInFirstWeek:function(a){this.minimalDaysInFirstWeek!==a&&(this.minimalDaysInFirstWeek=a,this.fieldsComputed=!1)},getMinimalDaysInFirstWeek:function(){return this.minimalDaysInFirstWeek},
getWeeksInWeekYear:function(){var a=this.getWeekYear();if(a===this.get(g))return this.getActualMaximum(o);var b=this.clone();b.setWeekDate(a,2,this.get(x));return b.getActualMaximum(o)},getWeekYear:function(){var a=this.get(g),b=this.get(o),c=this.get(h);c===e.JANUARY?52<=b&&--a:c===e.DECEMBER&&1===b&&++a;return a},setWeekDate:function(a,b,c){if(c<e.SUNDAY||c>e.SATURDAY)throw Error("invalid dayOfWeek: "+c);var d=this.fields,f=this.clone();f.clear();f.setTimezoneOffset(0);f.set(g,a);f.set(o,1);f.set(x,
this.getFirstDayOfWeek());a=c-this.getFirstDayOfWeek();0>a&&(a+=7);a+=7*(b-1);0!==a?f.add(v,a):f.complete();d[g]=f.get(g);d[h]=f.get(h);d[i]=f.get(i);this.complete()},clone:function(){void 0===this.time&&this.computeTime();var a=new e(this.timezoneOffset,this.locale);a.setTime(this.time);return a},equals:function(a){return this.getTime()===a.getTime()&&this.firstDayOfWeek===a.firstDayOfWeek&&this.timezoneOffset===a.timezoneOffset&&this.minimalDaysInFirstWeek===a.minimalDaysInFirstWeek},clear:function(a){void 0===
a?this.field=[]:this.fields[a]=void 0;this.time=void 0;this.fieldsComputed=!1}};var D=e.prototype;p.each(",Year,Month,DayOfMonth,HourOfDay,Minutes,Seconds,Milliseconds,WeekOfYear,WeekOfMonth,DayOfYear,DayOfWeek,DayOfWeekInMonth".split(","),function(a,b){if(a){D["get"+a]=function(){return this.get(b)};D["isSet"+a]=function(){return this.isSet(b)};D["set"+a]=function(a){return this.set(b,a)};D["add"+a]=function(a){return this.add(b,a)};D["roll"+a]=function(a){return this.roll(b,a)}}});return e});
